/**
 * create by hp
 * date 2020/3/7 12:30
 * @type {string[]}
 */

import {rootPath} from "./rootPath"
import * as fs from 'fs'
import {evnArray} from "./env"

const cleanDist = (evn: String) => {
  if (!evnArray.includes(evn)) throw new Error(`${evn}环境不存在，请检查`)
  const distPath = `${rootPath}dist-${evn}`

  if (fs.existsSync(distPath)) {
    try {
      fs.rmdirSync(distPath, {
        recursive: true
      })
    } catch (e) {
      throw `删除${distPath}文件夹失败，检查是否被其他程序占用`
    }
  }
}

export {
  cleanDist
}
